home *** CD-ROM | disk | FTP | other *** search
- Path: news1.h1.usa.pipeline.com!usenet
- From: grantp@usa.pipeline.com(Pete)
- Newsgroups: comp.lang.c++
- Subject: Re: Forced override?
- Date: 5 Mar 1996 22:44:20 GMT
- Organization: Kalevi, Inc.
- Message-ID: <4hig44$hr9@news1.usa.pipeline.com>
- References: <m1ybpgkvpa.fsf@zoger.ipost.com>
- NNTP-Posting-Host: pipe16.h1.usa.pipeline.com
- X-PipeUser: grantp
- X-PipeHub: usa.pipeline.com
- X-PipeGCOS: (Pete)
- X-Newsreader: Pipeline v3.5.0
-
- On Mar 04, 1996 20:30:57 in article <Forced override?>,
- 'bobg@zoger.ipost.com (Bob Glickstein)' wrote:
-
-
- >Quick question: is it possible to declare a virtual member function in
- >such a way that derived classes are *required* to override it? This
- >would have to work for classes both directly and indirectly derived.
-
- No. You can only force the function to be defined for each instantiated
- object. Examples (look at D. Override inherited from C):
-
- class A {
- public: virtual int foo() = 0; }; // pure virtual, must be overridden
-
- class B : public A {}; // foo not defined - can't instantiate
-
- class C : public B {
- public: virtual int foo(); };
- // C is to be instantiated so definition for foo() required
-
- class D : public C
- { };
-
-
-
- int main()
- {
- B b; // illegal -- no foo
- C c; // Ok. obviously
- D d; // Ok, uses C::foo()
- return 0;
- }
-
- --
- Pete Grant
- Kalevi, Inc.
- Software Engineering & development
-